package cn.edu.scujcc.customofsichuan.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

import cn.edu.scujcc.customofsichuan.Entity.Comment;
import cn.edu.scujcc.customofsichuan.R;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.myHolder>{
    List<Comment> commentList;
    Context context;

    public CommentAdapter(List<Comment> commentList,Context context) {
        this.commentList = commentList;
        this.context=context;
    }

    @NonNull
    @Override
    public myHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_item, parent, false);
        myHolder myHolder=new myHolder(view);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull myHolder holder, int position) {
        Comment comment=commentList.get(position);
        Glide.with(context).load(comment.getHead_img()).circleCrop().into(holder.head);
        holder.userName.setText(comment.getUserName());
        holder.content.setText(comment.getContent());
        holder.date.setText(comment.getDate());


    }

    @Override
    public int getItemCount() {
        return commentList.size();
    }

    class myHolder extends RecyclerView.ViewHolder{
        ImageView head;
        TextView userName;
        TextView content;
        TextView date;
        public myHolder(@NonNull View itemView) {
            super(itemView);
            head = itemView.findViewById(R.id.comment_user_head);
            userName = itemView.findViewById(R.id.comment_user_name);
            content=itemView.findViewById(R.id.comment_content);
            date=itemView.findViewById(R.id.comment_time);


        }
    }

}
